import { PageConfig } from 'next';
import an48 from '@mmstudio/an000048';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import getuser from '../../../atoms/getuser';

const logger = anylogger('pages/api/account/userinfo.api');

export type Result = Omit<ITbfduser, 'psw'> & { role: string; };

/**
 * 获取用户信息
 */
const handler = an48<Result>();

handler.get(async (req, res) => {
	try {
		logger.debug('msg cookies:', req.cookies);
		const user = await getuser(req);
		logger.debug('user info:', user);
		res.status(200).json(user);
	} catch (error) {
		logger.error(error);
		res.status(200).json({
			picture: '',
			email: '',
			name: '',
			phone: '',
			role: '',
			sex: 0,
			userid: ''
		});
	}
});

export const config = {} as PageConfig;

export default handler;
